package com.czq.gulimail.gulimailmember.controller;

import java.util.Arrays;
import java.util.Map;

import com.czq.gulimail.gulimailmember.feign.CouponFeignService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.*;

import com.czq.gulimail.gulimailmember.entity.MemberEntity;
import com.czq.gulimail.gulimailmember.service.MemberService;
import com.czq.common.utils.PageUtils;
import com.czq.common.utils.R;



/**
 * 会员
 *
 * @author czq
 * @email 1807099124@qq.com
 * @date 2024-09-26 17:12:10
 */
@RestController
@RequestMapping("gulimailmember/member")
@RefreshScope
public class MemberController {
    @Autowired
    private MemberService memberService;

    @Autowired
    private CouponFeignService couponFeignService;

    @Value("${member.name}")
    private String name;

    @Value("${member.age}")
    private String age;


    /**
     * 本地远程调用测试
     * @return
     */
    @GetMapping("/coupon")
    public R coupon(){
        MemberEntity memberEntity = new MemberEntity();
        memberEntity.setNickname("czq");
        R r = couponFeignService.couponList();
        return R.ok().put("member", memberEntity).put("coupon", r.get("yhq"));
    }


    /**
     * 本地nacos配置中心测试
     * @return
     */
    @GetMapping("/nacos")
    public R nacos(){
        return R.ok().put("name", name).put("age", age);
    }




    /**
     * 列表
     */
    @RequestMapping("/list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = memberService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    public R info(@PathVariable("id") Long id){
		MemberEntity member = memberService.getById(id);

        return R.ok().put("member", member);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    public R save(@RequestBody MemberEntity member){
		memberService.save(member);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    public R update(@RequestBody MemberEntity member){
		memberService.updateById(member);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    public R delete(@RequestBody Long[] ids){
		memberService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

}
